<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <meta name="csrf_token" id="token" content="{{ csrf_token() }}">
    @include('public.h5_head')
    <title>支付详情</title>
    <script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/rem.js"></script>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/commoncss/common.css"/>
    <link rel="stylesheet" type="text/css" href="{{ env('CDN_DOMAIN_NAME') }}/css/offline.css"/>
</head>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/iscroll.js"></script>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/app.js"></script>
<script src="{{ env('CDN_DOMAIN_NAME') }}/js/commonjs/common.js"></script>
<body>
<div id="offline_box">
    <div class="wrap">
        <div class="offline">
            <ul class="offline_ul">
                <li class="offline_li off_li">应付</li>
                <li class="offline_li">
                    <div class="offline_price">商品金额：<span style="color:#EA294B;">￥{{sprintf('%.2f',$orders->actual_price) }}</span></div>
                    <div class="offline_freight">实际运费：<span class="actual_freight" style="color:#EA294B;">@if($orders->postage_actual)￥{{ sprintf('%.2f',$orders->postage_actual) }} @else N/A @endif</span></div>
                </li>
                @if($orders->is_owe)
                    <li class="offline_li">
                        <div class="offline_price">首付金额：<span style="color:#EA294B;">￥{{sprintf('%.2f',$orders->downpayment) }} </span></div>
                        <div class="offline_ratio">首付比例：{{ sprintf('%.2f',$orders->downpayment/$orders->actual_price) *100 }}%</div>
                    </li>
                @endif
                <li class="offline_li off_li">实付</li>
                <li class="offline_li">
                    <div class="offline_pay">
                        @if($orders->is_owe)
                            付款金额：￥<input class="offline_inp1" readonly type="tel" placeholder="请填写付款金额" maxlength="12" value="{{ sprintf('%.2f',$orders->downpayment) }}" />
                        @else
                            付款金额：￥<input class="offline_inp1" type="tel" placeholder="请填写付款金额" maxlength="12" value="@if($orders->paid && $orders->is_owe==0){{sprintf('%.2f',$orders->paid)}}@endif" />
                        @endif
                    </div>
                    <div class="offline_peas">运费豆：<span class="peas">{{ $userinfo->postage_bean }}</span></div>
                </li>
                <li class="offline_li">
                    <div class="offline_pay">付款运费：￥<input class="offline_inp2" type="tel" placeholder="请填写运费(整数)" maxlength="3" value="@if($orders->paid){{sprintf('%.2f',$orders->postage_estimate) }}@endif" /></div>
                    @if(in_array($orders->status, [1,2]))
                        <div class="offline_peas"><a class="offline_btn1" href="javascript:;">确认付款</a></div>
                    @elseif(in_array($orders->status, [3,4,5,6,7]))
                        <span style="float:right;color:#1aad1a;">已付款</span>
                    @endif
                </li>
                @if($orders->paid > 0 && $orders->paid < $orders->actual_price)
                    <li class="offline_li offline_hidden" style="border-top:1px solid #ccc;">
                        @if($orders->is_owe)
                            <div class="offline_pay">付款金额：<span class="offline_inp3">￥{{sprintf('%.2f',$orders->actual_price - $orders->downpayment) }}</span></div>
                            <div class="offline_peas">
                                @if($orders->actual_price != $orders->paid)
                                    <a class="offline_btn2" href="javascript:;">确认付款</a>
                                @else
                                    <span style="float:right;color:#1aad1a;">已付款</span>
                                @endif
                            </div>
                        @elseif(isset($offspring))
                            <div class="offline_pay">付款金额：<span class="offline_inp3">￥{{sprintf('%.2f',$offspring->price) }}</span></div>
                            <div class="offline_peas">
                                @if($orders->actual_price != $orders->paid)
                                    <a class="offline_btn2" href="javascript:;">确认付款</a>
                                @else
                                    <span style="float:right;color:#1aad1a;">已付款</span>
                                @endif
                            </div>
                        @endif
                    </li>
                @endif
                <li class="offline_li" style="background:#f1f1f1;">剩余</li>
                <li class="offline_li">
                    <div class="offline_residue">剩余金额：<span style="color:#ea294b">￥{{ sprintf('%.2f',$orders->actual_price - $orders->paid) }}</span></div>
                </li>
            </ul>
        </div>
    </div>
    <div class="offline_hide" style="display:none;">
        <p class="offline_pass"></p>
        <p class="offline_ok">确定</p>
    </div>
    <div class="offline_mask" style="display:none;"></div>
    <div class="delDiv" style="display:none;">
        <div class="delDiv_tip">是否确认付款？</div>
        <div class="delDiv_info">
            <span id="" class="delDiv_info_left">
                <input id="btnCancel" type="button" value="取 消" class="btn-green btnCancel" />
            </span>
            <span id="" class="delDiv_info_right">
                <input id="btnDelTrue" type="button" value="确 认" class="btn-green btnDelTrue" />
            </span>
        </div>
    </div>
</div>
<script>
    scroll();
    $(".offline_inp2").bind("input","onpropertychange",function(){
        $(this).val($(this).val().replace(/[^\d]/g,""));
    })
    $('.offline_btn1').click(function () {
        var val=$(".offline_inp2").val();
        if(val==''){
            $(".offline_pass").html("运费不能为空");
            $(".offline_hide").show();
            $(".offline_mask").show();
        }else{
            var shoud_price='{{ sprintf('%.2f',$orders->actual_price) }}'
            var product_price = $('.offline_inp1').val();/*填写金额*/
            if( ( Number(product_price) - Number(shoud_price) ) > 0 ){
                $(".offline_pass").html("付款金额不能大于商品金额");
                $(".offline_hide").show();
                $(".offline_mask").show();
            }else{
                $(".delDiv").show();
                $(".offline_mask").show();
                $(".btnDelTrue").click(function() {
                    $(".delDiv").hide();
                    $(".offline_mask").hide();
                    var order_id = '{{ $orders->id }}';
                    var product_price = $('.offline_inp1').val();/*填写金额*/
                    var postage_price = $('.offline_inp2').val();
                    $.ajax({
                        url:'/Business/offline_payment',
                        type:'POST',
                        data:{product_price:product_price,postage_price:postage_price,order_id:order_id},
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                        },
                        dataType:'json',
                        success:function(data){
                            if(data.success == true){
                                $(".offline_inp1").attr("readonly",true);
                                $(".offline_inp2").attr("readonly",true);
                                window.location.reload();
                            }else{
                                $(".offline_pass").html(data.msg);
                                $(".offline_hide").show();
                                $(".offline_mask").show();
                            }
                        }
                    })
                })
            }
        }
    })
    $('.offline_btn2').click(function () {
        $(".delDiv").show();
        $(".offline_mask").show();
        $(".btnDelTrue").click(function() {
            $(".delDiv").hide();
            $(".offline_mask").hide();
            var owe_order_id = '{{ $orders->id }}';
            var is_owe = '{{ $orders->is_owe }}'
            $.ajax({
                url:'/Business/surplus_owe',
                type:'POST',
                data:{owe_order_id:owe_order_id,is_owe:is_owe},
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf_token"]').attr('content')
                },
                dataType:'json',
                success:function(data){
                    if(data.success == true){
                        window.location.reload();
                    }else{
                        $(".offline_pass").html(data.msg);
                        $(".offline_hide").show();
                        $(".offline_mask").show();
                        $(".offline_ok").click(function(){
                            $(".offline_hide").hide();
                            $(".offline_mask").hide();
                            window.location.reload();
                        })
                    }
                }
            })
        })
    })
    //点击确定隐藏
    $(".offline_ok").click(function(){
        $(".offline_hide").hide();
        $(".offline_mask").hide();
    })
    $(".btnCancel").click(function(){
        $(".delDiv").hide();
        $(".offline_mask").hide();
    })
</script>
</body>
</html>
